<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="订单编号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户评分" prop="star"  align="center">
        <!-- <el-input
          v-model="queryParams.star"
          placeholder="请输入用户评分"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.star" clearable placeholder="请选择评分" @change="changeScore">
          
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        
      </el-form-item>
      <!-- <el-form-item > -->
         <!-- <el-rate v-model="queryParams.star" allow-half /> -->
       <!-- {{queryParams.star}} -->
      <!-- </el-form-item> -->
      <!-- <el-form-item label="是否删除" prop="isDeleted">
        <el-input
          v-model="queryParams.isDeleted"
          placeholder="请输入是否删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> 
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:comment:add']"
        >新增</el-button>
        
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          
        >修改</el-button>
        <!-- v-hasPermi="['system:comment:edit']" -->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        
        >删除</el-button>
          <!-- v-hasPermi="['system:comment:remove']" -->
      </el-col>
      <el-col :span="1.5">
        <!-- <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
         
        >导出</el-button> -->
         <!-- v-hasPermi="['system:comment:export']" -->
      </el-col>
      <right-toolbar v-model="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="commentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column show-overflow-tooltip label="评价编号" align="center" prop="commentId" />
      <el-table-column show-overflow-tooltip label="订单编号" align="center" prop="orderId" />
      <el-table-column show-overflow-tooltip label="匿名评价" align="center" prop="anonymousComment" />
      <!-- <el-table-column label="用户评分" align="center" prop="star" /> -->
      <!-- <el-rate v-model="form.star" allow-half /> -->
      <el-table-column label="用户评分"  show-overflow-tooltip  >
					<template #default="scope">
            <el-tag type="info" size="large" v-if="!scope.row.star">未评分</el-tag>
             <el-rate v-else v-model="scope.row.star" allow-half disabled ></el-rate>
					</template>
			</el-table-column>
      <el-table-column show-overflow-tooltip label="评价内容" align="center" prop="buyerContent"/>
      <el-table-column show-overflow-tooltip  label="回复内容" align="center" prop="sellerComment" />
      <!-- <el-table-column show-overflow-tooltip label="图片地址" align="center" prop="pictureUrl" /> -->
      <el-table-column label="评论图片"  show-overflow-tooltip  >
					<template #default="scope">
              <el-image
              style="width: 50px; height: 50px"
              src="https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg"
              :initial-index="4"
             :preview-src-list="scope.row.pictureUrl.split(',')"
              fit="cover"
              >
             </el-image>
             <!-- {{typeof scope.row.pictureUrl }} -->
               <!-- str.split(",") :preview-src-list="['https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg']" -->
					</template>
			</el-table-column>

  
    
      <!-- <el-table-column label="是否删除" align="center" prop="isDeleted" /> -->
      <el-table-column prop="createTime" label="评论时间" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
           
          >回复</el-button>
           <!-- v-hasPermi="['system:comment:edit']" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            
          >删除</el-button>
          <!-- v-hasPermi="['system:comment:remove']" -->
        </template>
      </el-table-column>
    </el-table>


     <el-pagination
      v-model:currentPage="queryParams.pageNum"
      v-model:page-size="queryParams.pageSize"
      :page-sizes="[5, 10, 20, 30]"
      :disabled="disabled"
    background
      layout="sizes, prev, pager, next"
      :total="total"
     @size-change="getList"
      @current-change="getList"
 
    >
    </el-pagination>
    
    <!-- <pagination
      v-show="total>0"  :background="background"
      :total="total"  :small="small"
      :current="queryParams.pageNum"
      :pagesize="queryParams.pageSize"
      @pagination="getList" @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />  -->

    <!-- 添加或修改订单评论对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单编号" readonly/>
        </el-form-item>
         <el-form-item label="用户评分" prop="star">
             <el-tag type="info" size="large" v-if="!form.star">未评分</el-tag>
             <el-rate v-else v-model="form.star" allow-half disabled ></el-rate>
        </el-form-item> 
        <el-form-item label="评价内容" prop="buyerContent">
          <el-input v-model="form.buyerContent" type="textarea" placeholder="请输入内容" readonly/>
        </el-form-item>
        <el-form-item label="商家回复" prop="sellerComment">
          <el-input v-model="form.sellerComment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="评论图片" prop="pictureUrl">
            <div style="display:flex;flex-wrap:wrap;">
              <div style="margin-right:20px" v-for="(item,index) in ['https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg']" :key="index">
               <el-image
                style="width: 100px; height: 100px"
                :src="item"
                :initial-index="4"
                fit="cover"
              ></el-image>
            </div>
            </div>
          <!-- <el-input v-model="form.pictureUrl" type="textarea" placeholder="请输入内容" /> -->
        </el-form-item>
        <!-- <el-form-item label="是否删除" prop="isDeleted">
          <el-input v-model="form.isDeleted" placeholder="请输入是否删除" />
        </el-form-item> -->
      </el-form>
       <!-- <template v-slot:header> -->
      <!-- <div slot=footer class="dialog-footer"> -->
      <template v-slot:footer class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </template> 
    </el-dialog>
  </div>
</template>

<script>
import { listComment, getComment, delComment, addComment, updateComment } from "/@/api/system/comment";

export default {
  name: "Comment",
  data() {
    return {
      options : [
        {
          value: null,
          label: "全部",
        },
        {
          value: '0',
          label: '0分',
        },
        {
          value: '1',
          label: '1分',
        },
        {
          value: '2',
          label: '2分',
        },
        {
          value: '3',
          label: '3分',
        },
        {
          value: '4',
          label: '4分',
        },
        {
          value: '5',
          label: '5分',
        }
        ],
      scoreFlag: null, // 0 都选，1选评分，2未评分
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单评论表格数据
      commentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        anonymousComment: null,
        star: null,
        buyerContent: null,
        sellerComment: null,
        pictureUrl: null,
        isDeleted: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.queryParams.star = null;
  },
  methods: {
    /** 查询订单评论列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams);
      listComment(this.queryParams).then(response => {
        this.commentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.scoreFlag = null;
      this.form = {
        commentId: null,
        orderId: null,
        anonymousComment: null,
        star: null,
        buyerContent: null,
        sellerComment: null,
        pictureUrl: null,
        isDeleted: null,
        createTime: null,
        updateTime: null
      };
      // this.resetForm("form");
    },
    /** 分数的值改变*/
    changeScore() {
      console.log("分值改变了");
      // this.queryParams.star = null; 
      console.log(this.queryParams.star);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        anonymousComment: null,
        star: null,
        buyerContent: null,
        sellerComment: null,
        pictureUrl: null,
        isDeleted: null,
      };
      // this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.commentId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单评论";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const commentId = row.commentId || this.ids
      getComment(commentId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单评论";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.commentId != null) {
            updateComment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addComment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const commentIds = row.commentId || this.ids;
      this.$modal.confirm('是否确认删除订单评论编号为"' + commentIds + '"的数据项？').then(function() {
        return delComment(commentIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/comment/export', {
        ...this.queryParams
      }, `comment_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>

</style>